package com.jin.webvideo.base.httpclient;

import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;

import java.io.IOException;

public class ProxyResponseHandler<T> implements ResponseHandler {
    private ResponseHandler<T> handler;
    private HttpClient httpClient;
    private HttpRequest httpRequest;
    private HttpSurroundHandler httpSurroundHandler;
    public ProxyResponseHandler(HttpClient httpClient, HttpSurroundHandler httpSurroundHandler, HttpRequest request, ResponseHandler<T> handler) {
        this.httpClient = httpClient;
        this.httpSurroundHandler = httpSurroundHandler;
        this.httpRequest = request;
        this.handler = handler;
    }
    @Override
    public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
        this.httpSurroundHandler.handleResponse(httpClient, httpRequest, response);
        return handler.handleResponse(response);
    }
}
